package routes

import akka.actor.ActorSystem
import akka.http.scaladsl.server._
import akka.stream.Materializer
import common.RoutesDefinition
import models._

class GzhInfoRoutes(
    implicit
    val system: ActorSystem,
    val materializer: Materializer,
    val _GzhInfos: GzhInfos
) extends RoutesDefinition {

  val routes: Route = pathPrefix("gzhs") {
    (pathEndOrSingleSlash & post) {
      entity(as[GzhInfo]) { info ⇒
        serviceAndComplete(_GzhInfos.save(info))
      }
    } ~
      (pathEndOrSingleSlash & post) {
        entity(as[List[GzhInfo]]) { infos ⇒
          serviceAndComplete(_GzhInfos.save(infos))
        }
      } ~
      (pathEndOrSingleSlash & get) {
        serviceAndComplete(_GzhInfos.findAll)
      } ~
      (path(Segment) & get) { appid ⇒
        serviceAndComplete(_GzhInfos.findOne(appid))
      } ~
      (path(Segment) & put) { appid ⇒
        entity(as[GzhInfo]) { info ⇒
          serviceAndComplete(_GzhInfos.updateOne(appid, info))
        }
      } ~
      (path(Segment) & delete) { appid ⇒
        serviceAndComplete(_GzhInfos.deleteOne(appid))
      }
  }
}
